<?php 
if(!defined('BASEPATH'))
		exit('No direct script access allowed');
	class Pricing extends CI_Controller {
		function __construct(){
			session_start();
			parent::__construct();
		}
		
		function index($query_id=0, $order_by='start_date', $sort_order='asc', $current_page=0){
			$search_by='';
			$search_by_value='';
				if($query_id == '0'){		
					//echo '<pre>';print_r($_SESSION);exit;
					unset($_SESSION['search']);
				}else{
					if(isset($_SESSION['search'])){
					$array = $_SESSION['search'];
					//echo '<pre>';print_r($_SESSION);exit;
					$search_by = $array['search_by'];
					$search_by_value = $array['search'];
					//echo '<pre>';print_r($search_by_value);exit;
					}
				}
					$results_per_page = 3;
		
			$url = CURL_URL;
			$data = array('www-command'=>'events-all_event_price', 'current_page'=>$current_page, 'results_per_page'=>$results_per_page, 'order_by'=>$order_by, 'sort_order'=>$sort_order, 'search_by'=>$search_by, 'search_by_value'=>$search_by_value);
			
			$string = http_build_query($data);
			//echo '<pre>';print_r($data);exit;
			$ch = curl_init($url);
			curl_setopt($ch,CURLOPT_POST,true);
			curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
			curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
			$response= json_decode(curl_exec($ch));
			//echo '<pre>';print_r($response);exit;
			curl_close($ch);
			if($response->message !== 'No offers'){
			$this->load->library('pagination');			
			$config['base_url'] = base_url().'admin/pricing/index/'.$query_id.'/'.$order_by.'/'.$sort_order;
			$config['per_page'] = $results_per_page;
			$config['total_rows']  = $response->total;
			$config['uri_segment'] = 7;
			$config['num_links'] = 1;
			$config['prev_link'] = 'Previous';
			$config['next_link'] = 'Next';
			$config['first_link'] = 'First';
			$config['last_link'] = 'Last';
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			$data['events_all_event_price'] = $response;
			$data['offer'] = '';
			}else{
				$data['offer'] = 1;
				$data['events_all_event_price'] = '';
			}
			//echo '<pre>';print_r($data);exit;
			$data['sort_order'] = $sort_order;
			$data['order_by'] = $order_by;
			$data['query_id'] = $query_id;
			$data['search_by'] = $search_by;
			$data['search_by_value'] = $search_by_value;
			$data['pricing_fields'] = array('pricing_name'=>'Name', 'event_type_id'=>'Type', 'start_date'=>'Start Date', 'status'=>'Status');
			$data['status'] = array(1=>'Active', 0=>'In-active');
			$this->load->view('admin/pricing', $data);
		}
		
		function create_pricing_page(){
				$url = CURL_URL;
					$data = array('www-command'=>'events-get_event_type_list'
					);
					//echo '<pre>';print_r($data);exit;
					$string = http_build_query($data);
					$ch = curl_init($url);
					curl_setopt($ch,CURLOPT_POST,true);
					curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
					curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
					$response= json_decode(curl_exec($ch));
					//echo '<pre>';print_r($response);exit;
					$data['get_event_type_list'] = $response;
					curl_close($ch);
				$this->load->view('admin/create_pricing_page', $data);
		}
}